package com.yx.learn.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Department entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "tdepartment", catalog = "yx_01")
public class Department implements java.io.Serializable {

	// Fields

	private Integer id;
	private Company company;
	private String deptNo;
	private String deptName;
	private Integer pid;
	private String memo;
	private Set<User> users = new HashSet<User>(0);

	// Constructors

	/** default constructor */
	public Department() {
	}

	/** minimal constructor */
	public Department(Integer id, Company company, String deptNo,
			String deptName, Integer pid) {
		this.id = id;
		this.company = company;
		this.deptNo = deptNo;
		this.deptName = deptName;
		this.pid = pid;
	}

	/** full constructor */
	public Department(Integer id, Company company, String deptNo,
			String deptName, Integer pid, String memo, Set<User> users) {
		this.id = id;
		this.company = company;
		this.deptNo = deptNo;
		this.deptName = deptName;
		this.pid = pid;
		this.memo = memo;
		this.users = users;
	}

	// Property accessors
	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "companyID", nullable = false,referencedColumnName="id")
	public Company getCompany() {
		return this.company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	@Column(name = "deptNo", nullable = false, length = 20)
	public String getDeptNo() {
		return this.deptNo;
	}

	public void setDeptNo(String deptNo) {
		this.deptNo = deptNo;
	}

	@Column(name = "deptName", nullable = false, length = 64)
	public String getDeptName() {
		return this.deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	@Column(name = "pid", nullable = false)
	public Integer getPid() {
		return this.pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	@Column(name = "memo", length = 200)
	public String getMemo() {
		return this.memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	//@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "department")
	@OneToMany(targetEntity=User.class,mappedBy="department",cascade=CascadeType.ALL)
	public Set<User> getUsers() {
		return this.users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

}